#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;

const int N = 1e5 + 10;
int arr[N];
int n;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> arr[i];
    sort(arr + 1, arr + 1 + n);
    LL ret = 0;
    for (int i = 1; i <= n; i++)
    {
        ret += abs(arr[(1 + n) / 2] - arr[i]);
    }
    cout << ret << endl;
    return 0;
}